﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.UC.货号管理.service;

namespace DXApplicationTangche.UC.货号管理
{
    public partial class Form成衣异常提交 : DevExpress.XtraEditors.XtraForm
    {
        private List<GarmentExceptionDTO> garmentExceptionDTOs = new List<GarmentExceptionDTO>();//异常列表
        public String barcode { get; set; }//成衣码
        public String projectInstanceCode { get; set; }//工序code
        public Form成衣异常提交(String barcode,String projectInstanceCode, List<GarmentExceptionDTO> garmentExceptionDTOs)
        {
            InitializeComponent();
            this.barcode = barcode;
            this.textBox问题水洗.Text = this.barcode;
            this.projectInstanceCode = projectInstanceCode;
            this.garmentExceptionDTOs = garmentExceptionDTOs;
            this.gridControl成衣异常列表.DataSource = this.garmentExceptionDTOs;
        }
        
        private void Form成衣异常提交_Load(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(this.textBox问题水洗.Text))
            {
                this.ActiveControl = this.textBox问题水洗;
            }
            else
            {
                this.ActiveControl = this.textBox扫描员工牌;
            }
        }
        private void textBox问题水洗_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (!String.IsNullOrWhiteSpace(this.textBox问题水洗.Text))
                {
                    this.barcode = this.textBox问题水洗.Text.Trim();
                    this.ActiveControl = this.textBox扫描员工牌;
                }
            }
        }
        private void textBox扫描员工牌_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (String.IsNullOrEmpty(this.barcode))
                {
                    MessageBox.Show("请先扫描有问题的水洗标");
                    return;
                }
                if (!String.IsNullOrWhiteSpace(this.textBox扫描员工牌.Text))
                {
                    if (this.garmentExceptionDTOs.Count <= 0)
                    {
                        this.garmentExceptionDTOs.Add(new GarmentExceptionDTO("成衣异常", ""));
                    }
                    try
                    {
                        成衣异常Service.saveGenerateGarmentException(
                            this.barcode,
                            this.textBox扫描员工牌.Text.Trim(),
                            this.projectInstanceCode,
                            this.garmentExceptionDTOs
                            );
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    this.garmentExceptionDTOs.Clear();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("请扫描员工牌");
                    return;
                }
                
            }
        }

        
    }
}